package com.itheima.dubbo.web;

import com.itheima.dubbo.User;
import com.itheima.dubbo.UserFace;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {

    @DubboReference
    //@DubboReference(timeout = 1500)
//    @DubboReference(methods = {
//            @Method(name = "getById",timeout = 1500 )
//    })
    //@DubboReference(version = "1.0.0")
    UserFace userFace;


    @GetMapping("hello")
    public String hello(String username){
        return userFace.hello(username);

    }

    @GetMapping("getById")
    public User getById(Long id){
        User user = new User();
        user.setId(id);

        RpcContext.getContext().setAttachment("itname","程序员");
        return userFace.getById(user);

    }
}
